<?php
namespace service\Address;


class ParseRules
{
    /**
     * 街道匹配规则
     * @var array
     */
    public static $street = [
        '([^街路区镇\d]{2,6}(?:路|街(?!道)|大道)\d{1,5}(?:弄|号|巷))', // xx[xxxx](路|街)1[1234](弄|号|巷)
        '(\d{1,5}(?:弄|巷)\d{1,4}(?:支弄|号))', //1[2345](弄|巷)1[234](支弄|号)
        '([^街路区镇\d]{0,8}(?:\d{1,5}(?:弄|巷))|(?<=\D)\d{1,5}号)', //
    ];

    /**
     * 楼栋匹配规则
     * @var array
     */
    public static $building = [
        '((?:[A-Z]区)?\d{1,4}(?:号楼|D|#|栋|H|幢|单元)(?:\w+(?:单元|区|座|栋|幢|梯|号))?)',
        '(\d+号(?:[A-Z]区))',
        '(?<!楼|层|F)([A-Z](?:座|栋|单元|梯|幢|D|#))',
        '(^\d{1,4}号)(?:[1-9]\d?(?:楼|层|F|单元)|[1-9]\d?[012]\d室?|[A-H]单元)',
    ];

    /**
     * 道路级别的建筑匹配
     * @var array
     */
    public static $road_building = [
        '((?:[A-Z]区)?\d{1,4}(?:号楼|D|#|栋|H|幢|单元)(?:\w+(?:单元|区|座|栋|幢|梯|号))?)',
        '(\d+号(?:[A-Z]区))',
        '([A-Z](?:座|栋|H|幢|D|#))',
        '(^\d{1,4}号)(?:[1-9]\d?[012]\d室?)'
    ];

    /**
     * 层匹配规则
     * @var array
     */
    public static $floor = [
        '((?:地下|负|B)?\d{1,2}(?:楼|层|F|\\\')(?:[A-G](?:座|室|单元)?|\d{1,4}室)?)',
        '([1-9]\d?[012]\d(?:-\d{3,4}室?|室|宿舍))',
        '(?<!\d|路|道|街|弄|巷|区)([1-9]\d?[012]?\d(?:-\d{1,2}(?:号|室)?|号|室)?$)',
        '(?<!\d)([1-9][012]?\d?-\d{1,2}$)',
    ];

    /**
     * 门牌号匹配规则
     * @var array
     */
    public static $door = [
        '(\d+室)',
        '(?<=弄|号)(\d+[\D]*)',
        '([A-Z]单元)',
    ];

    /**
     * 邮编匹配规则
     * @var array
     */
    public static $post_code = [
        '(\(?\d{6}\)?)'
    ];

    /**
     * property getter
     * @param string $property
     * @return mixed
     */
    public static function get($property)
    {
        return static::${$property};
    }
}
